package de.wolvan.window;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.MalformedURLException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import de.wolvan.references.*;
import de.wolvan.tools.*;

public class InfoWindow extends JFrame implements ActionListener{
	
	public static InfoWindow frame;
	
	public static JButton toGoogleCode;
	public static JButton close;
	public static JButton sendMail;
	
	public static JTextArea infoText;
	public static JScrollPane scrollInfoText;
	
	
	public static void renderGUI() {
		frame = new InfoWindow("Program Info");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(600,300);
		frame.setLayout(null);
		frame.setVisible(true);
	}
	
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == toGoogleCode) {
			try {
				LinkTools.browse(new java.net.URL("https://code.google.com/p/ximd/"));
			} catch (MalformedURLException e1) {
				e1.printStackTrace();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			
		}
		if(e.getSource() == sendMail) {
				JOptionPane.showMessageDialog(null, "The automatic Mailto function is not yet implemented.\nYou can manually send your E-Mail to " + metadata.devMail, "Automatic mailto not implemented", 0, null);
		}
		if(e.getSource() == close) {
			frame.setVisible(false);
		}
	}
	
	public InfoWindow(String title) {
		super(title);
		
		toGoogleCode = new JButton("Go to Google Code");
		toGoogleCode.setBounds(10,160,270,40);
		toGoogleCode.addActionListener(this);
		add(toGoogleCode);
		
		sendMail = new JButton("Send E-Mail");
		sendMail.setBounds(300,160,270,40);
		sendMail.addActionListener(this);
		add(sendMail);
		
		close = new JButton("Close");
		close.setBounds(10,210,560,40);
		close.addActionListener(this);
		add(close);
		
		infoText = new JTextArea("== PROGRAM INFORMATION ==\n" + metadata.name + " " + metadata.version + "\nProgrammed by " + metadata.developer + "\nContact Mail: " + metadata.devMail + "\n" + metadata.additionalInfoText + "\n== XIM INFORMATION ==\nXIM Build: " + xim.build + "\nXIM Server: " + xim.serverFullPath);
		infoText.setBounds(10,10,560,140);
		infoText.setEditable(false);
		add(infoText);
		
		scrollInfoText = new JScrollPane(infoText);
		scrollInfoText.setBounds(infoText.getBounds());
		add(scrollInfoText);
	}

}
